<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="shortcut icon" href="/static/img/logo/favicon.ico" />
  <link rel="stylesheet" href="/static/assets/plugins/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="/static/css/footer.css">
  <link rel="stylesheet" href="/static/css/header.css">
  <title>论坛</title>
</head>

<body class="home">

<div style="width: 100%;height: 60%;">
    <div style="width: 300px; height: 100px; margin: 0 auto;margin-top: 15%;margin-bottom: 20%;">
        <div class="span4">
            <a href="/login">普通用户登录></a>
            <div class="input-prepend" style="width: 300px;">
                <span class="add-on">管理员账号：</span><input style="width: 200px" class="span2" id="uid"
                                                      size="16" type="text"
                                                      placeholder="账号">
            </div>
            <div class="input-prepend">
                <span class="add-on">管理员密码：</span><input style="width: 200px" class="span2" id="pwd"
                                                      size="16" type="password"
                                                      placeholder="密码">
            </div>
            <div style="width: 300px;padding: 20px;margin: 0 auto;">
                <button id="login-button" style="margin-right: 20px;margin-left: 20px;" class="btn btn-primary" type="submit">登录
                </button>
                <button id="register-button" style="margin-right: 20px;margin-left: 20px;" class="btn btn-primary btn-inverse"
                        type="submit">取消
                </button>
            </div>

        </div>
    </div>
</div>


<script src="/static/assets/plugins/jquery/jquery.min.js"></script>
<script>
    $('#login-button').click(function () {
       var uid = $('#uid').val();
       var pwd = $('#pwd').val();
       $.ajax({
            url: window.location.href,
            type: "POST",
            data: {'admin_id': uid, 'admin_pwd': pwd},
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    // csrf
            },
            success: function (data) {
                // data是服务器端返回的字符串
                if (!data.status) alert(data.msg);
                else window.location.href="/admin-home";
            }
        });
    });

    $('#register-button').click(function () {
       window.location.href = "/home";
    });

</script>
</body>
</html>
